 package com.oanda.blackberry.ui;
 
 import net.rim.device.api.system.Bitmap;
 import net.rim.device.api.ui.ContextMenu;
 import net.rim.device.api.ui.Field;
 import net.rim.device.api.ui.FieldChangeListener;
 import net.rim.device.api.ui.Font;
 import net.rim.device.api.ui.Graphics;
 import net.rim.device.api.ui.component.CheckboxField;
 
 public class BitmapCheckboxField extends CheckboxField
 {
   int width;
   int height;
   Bitmap selected = Bitmap.getBitmapResource("trades-row-selected-480x70.png");
   Bitmap notSelected = Bitmap.getBitmapResource("trades-row-480x70.png");
 
   private Bitmap selectedIcon = Bitmap.getBitmapResource("symbol-selected-29x29-p24.png");
   private Bitmap notSelectedIcon = Bitmap.getBitmapResource("symbol-notselected-29x29.png");
 
   boolean isSelected = false;
   private String label;
 
   public BitmapCheckboxField(String label, boolean checked, long style)
   {
     super(label, false, style);
 
     this.label = label;
 
     if (this.selected != null) {
       this.width = this.selected.getWidth();
       this.height = this.selected.getHeight();
     }
   }
 
   protected boolean keyChar(char key, int status, int time)
   {
     if (key == '\n') {
       if (getChangeListener() != null) {
         getChangeListener().fieldChanged(this, 0);
       }
       return true;
     }
     return super.keyChar(key, status, time);
   }
 
   public void paint(Graphics graphics)
   {
     graphics.setColor(4473924);
     graphics.fillRect(0, 0, this.width - 1, this.height - 1);
 
     if (this.isSelected) {
       if (this.selected != null) {
         graphics.drawBitmap(0, 0, this.width, this.height, this.selected, 0, 0);
       }
     }
     else if (this.notSelected != null) {
       graphics.drawBitmap(0, 0, this.width, this.height, this.notSelected, 0, 0);
     }
 
     if (getChecked())
       graphics.drawBitmap(20, (this.height - this.selectedIcon.getHeight()) / 2, this.selectedIcon.getWidth(), this.selectedIcon.getHeight(), this.selectedIcon, 0, 0);
     else {
       graphics.drawBitmap(20, (this.height - this.selectedIcon.getHeight()) / 2, this.selectedIcon.getWidth(), this.selectedIcon.getHeight(), this.notSelectedIcon, 0, 0);
     }
 
     Font f = Font.getDefault().derive(0, 24);
     graphics.setFont(f);
     graphics.setColor(16119285);
     graphics.drawText(this.label, 60, (this.height - f.getHeight()) / 2);
   }
 
   protected void layout(int maxWidth, int maxHeight) {
     setExtent(this.width, this.height);
   }
 
   public boolean isFocusable() {
     return true;
   }
 
   protected void onFocus(int direction)
   {
     super.onFocus(direction);
     this.isSelected = true;
     invalidate();
   }
 
   protected void onUnfocus() {
     super.onUnfocus();
     this.isSelected = false;
     invalidate();
   }
 
   protected void makeContextMenu(ContextMenu contextMenu)
   {
   }
}

